/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.pd.projectbuilder.main.util;

import com.jidesoft.swing.CheckBoxTree;
import cz.pd.projectbuilder.Davka;
import cz.pd.projectbuilder.beans.load.ProjectBean;
import java.util.Set;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

/**
 *
 * @author forrest
 */
public class ProjectUtils {

  public static Davka DAVKA = new Davka();

  public static void setSelectedCheckBoxes(CheckBoxTree checkBoxTree, Set<ProjectBean> selectedProjectBeans) {
    TreeModel model = checkBoxTree.getModel();
    Object root = model.getRoot();
    int childCount = model.getChildCount(root);
    for (int i = 0; i < childCount;
        i++) {
      Object child = model.getChild(root, i);
      if (child instanceof DefaultMutableTreeNode) {
        for (ProjectBean projectBean : selectedProjectBeans) {
          if (((ProjectBean) ((DefaultMutableTreeNode) child).getUserObject()).equals(projectBean)) {
            checkBoxTree.getCheckBoxTreeSelectionModel().clearSelection();
            checkBoxTree.getCheckBoxTreeSelectionModel().addSelectionPath(new TreePath(((DefaultMutableTreeNode) child).
                getPath()));
            break;
          }
        }
      }
    }
  }
}
